﻿using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;

namespace E.Story
{
    /// <summary>
    /// 基类分组
    /// </summary>
    public class BaseGroup : Group
    {
        /// <summary>
        /// 分组GUID
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 旧分组标题
        /// </summary>
        public string OldTitle { get; set; }

        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="position">坐标</param>
        public BaseGroup(string title, Vector2 position)
        {
            // 设置公共属性
            ID = GUID.Generate().ToString();
            this.title = title;
            OldTitle = title;
            SetPosition(new Rect(position, Vector2.zero));

            // 添加 USS 类
            headerContainer.AddToClassList("group__head-container");
        }

        #region 实用方法
        
        /// <summary>
        /// 获取分组数据
        /// </summary>
        /// <returns>分组数据</returns>
        public GroupData GetGroupData()
        {
            GroupData groupData = new()
            {
                GUID = ID,
                Title = title,
                Position = GetPosition().position
            };

            return groupData;
        }

        /// <summary>
        /// 设置错误样式
        /// </summary>
        public void SetErrorStyle()
        {
            headerContainer.AddClasses("error-bg");
        }

        /// <summary>
        /// 重置样式
        /// </summary>
        public void ResetStyle()
        {
            headerContainer.RemoveFromClassList("error-bg");
        }

        #endregion
    }
}